<?php
require_once '../../library/config.php';
require_once '../library/functions.php';

checkUser();

$action = isset($_GET['action']) ? $_GET['action'] : '';
echo $action;
switch ($action) {
	
	case 'addTopicS' :
		addTopicS();
		break;
		
	case 'modifyTopicS' :
		modifyTopicS();
		break;
		
	case 'deleteTopicS' :
		deleteTopicS();
		break;   

	default :
	    // if action is not defined or unknown
		// move to main TopicS page
		header('Location: index.php');
}


function addTopicS()
{
	$id   			= (int)$_GET['id'];
	$dv_id			= (int)$_POST['cboDept'];
    $madt    		= $_POST['txtMadt'];
	$tendt 			= $_POST['txtTendt'];
	$nguoithuchien 	= $_POST['txtNguoithuchien'];
	$namthuchien 	= $_POST['txtNamthuchien'];
	$gv_huongdan	= $_POST['txtGv_huongdan'];
	$ngaynghiemthu   = $_POST['txtNgaynghiemthu'];
	$giaithuong		= $_POST['txtGiaithuong'];
	
	$sql2   = "INSERT INTO detai_sv(madt, tendt, nguoithuchien, namthuchien, ngaynghiemthu, giaithuong, dv_id, gv_huongdan)
	          VALUES ('$madt', '$tendt', '$nguoithuchien', $namthuchien, '$ngaynghiemthu', '$giaithuong', $dv_id, '$gv_huongdan')";
	
	//echo $sql2; exit();
	$result2 = dbQuery($sql2);

	header("Location: index.php");	
}

//	Modify a TopicS

function modifyTopicS()
{
	$id   			= (int)$_GET['id'];
	$dv_id			= (int)$_POST['cboDept'];
    $madt    		= $_POST['txtMadt'];
	$tendt 			= $_POST['txtTendt'];
	$nguoithuchien 	= $_POST['txtNguoithuchien'];
	$namthuchien 	= $_POST['txtNamthuchien'];
	$gv_huongdan	= $_POST['txtGv_huongdan'];
	$ngaynghiemthu   = $_POST['txtNgaynghiemthu'];
	$giaithuong		= $_POST['txtGiaithuong'];
	
	$sql2   = "UPDATE detai_sv
               SET tendt = '$tendt', nguoithuchien = '$nguoithuchien', namthuchien = $namthuchien, gv_huongdan = '$gv_huongdan', ngaynghiemthu = '$ngaynghiemthu',giaithuong = '$giaithuong', dv_id = $dv_id
			   WHERE id = $id" ;		
			   //echo $sql2; exit();
	$result2 = dbQuery($sql2);
	
	
	header("Location: index.php");			  
}

//Delete TopicS
function deleteTopicS()
{
	if (isset($_GET['id']) && $_GET['id'] > 0) {
	$id = (int)$_GET['id'];
	} else {
		header('Location:index.php');
	}	
		
	$sql1 = "UPDATE detai_sv SET hieu_luc = 0 WHERE id = $id"; 

	dbQuery($sql1);
		
    header('Location: index.php'); 
}

?>